package com.ash.configuration;

import org.hibernate.validator.constraints.Length;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import java.util.List;

/**
 * https://www.baeldung.com/spring-enable-config-properties
 * 1. 编写 configurationProperties类
 * 2. 注入到容器
 *   - @EnableConfigurationProperties
 * 3. 支持list set map等复杂对象的注入和配置
 * @Author: Ashin
 * @Date: 2021/5/11
 * @Description: com.ashin.configuration
 * @Version: 1.0.0
 */
//@Valid 无效
@Validated
@ConfigurationProperties("myapp")
public class MyApp {

    @Length(max = 3)
    private String name;
    private Integer age;
    private Boolean sex;
    private List<String> house;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getSex() {
        return sex;
    }

    public void setSex(Boolean sex) {
        this.sex = sex;
    }

    public List<String> getHouse() {
        return house;
    }

    public void setHouse(List<String> house) {
        this.house = house;
    }

    @Override
    public String toString() {
        return "MyApp{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                ", house=" + house +
                '}';
    }
}
